package com.hejing.类的内部成员之四_代码块;

/**
 * ClassName: User
 * Package: com.hejing.类的内部成员之四_代码块
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-03-28 20:13
 * @Version: 1.0
 */
public class User {
    private String userName;
    private String password;

    private long registrationTime;  // 注册时间

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public long getRegistrationTime() {
        return registrationTime;
    }

    // 非静态代码块:
    {
        System.out.println("新用户注册");
        registrationTime = System.currentTimeMillis();  // 获取系统当前时间: 从1970-1-1 00:00:00到现在的毫秒数
    }

    // 无参构造器:
    public User() {
        userName = System.currentTimeMillis() + "";
        password = "123456";
    }

    // 有参构造器
    public User(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }


    public String getInfo() {
        return "用户名: " + userName + "\t密码: " + password + "\t注册时间: " + registrationTime;
    }
}
















